
class RegisterController {
    constructor($scope,$rootScope,$state,$timeout,UserService){
        Object.assign(this,{$scope,$rootScope,$state,$timeout,UserService});
        this.code = $state.params.code;
        this.username = null;
        this.password = null;
        this.nickname  =null;
        this.routeAterLogined="dashboard.entrance";
    }
    register(){
        //将this 赋值给self，在子函数中使用this，是引用子函数的this对象。
        let self = this;
        let param = {};
        param.username = self.username;
        param.password = self.password;
        param.nickname = self.nickname;
        param.code = self.code;

        this.UserService.register(param).then(_success).catch(_error);
        function _success(data) {
            if(data.success && data.success==true){
                layer.open({
                    type:0,
                    title:"注册成功",
                    content:"恭喜您已经注册成功了，3秒后将为你跳转到登录页面。",
                    btn:["立即登录"],
                    yes:function (index,layerno) {
                        layer.close(index);
                        self.$state.go("login");
                    },
                    time:3000,
                    end:function () {
                        self.$state.go("login");
                    }
                })
            }
        }
        function _error(reason) {
           console.log(reason);
        }
    }


}
RegisterController.$inject = ["$scope","$rootScope", '$state', '$timeout',"UserService"];

export default RegisterController;